# -- coding: utf-8 --
from kwdriven.kw_method import Action
from kwdriven.tools import DataParser


def run():
    paths = DataParser.read_csv('./scripts_path.txt', '# ')
    for path in paths:
        script = DataParser.read_csv(path, '# ')
        map = DataParser.read_json('./map.json')
        action = Action()  # 实例化动作类
        for step in script:
            ckw = step.split(',')[0]  # 获取中文关键字
            params = step.split(',')[1:]  # 获取从第一项之后的所有内容作为参数,它是一个列表
            temp = []
            if len(params) > 0:
                for item in params:
                    temp.append(item.strip())
            keyword = map[ckw]  # 根据映射字典获取英文关键字
            if hasattr(action, keyword):
                getattr(action, keyword)(*tuple(temp))  # 将列表先转化为元组，再通过*进行解包当做参数传递

if __name__ == '__main__':

    run()